package com.yanqingying.controller;

import com.yanqingying.aop.log;
import com.yanqingying.Dept;
import com.yanqingying.Result;
import com.yanqingying.service.DeptService;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 请求处理类
 */
@RequestMapping("/depts")
@RestController
public class DeptController {
    @Autowired
    private DeptService deptService;

    /**
     * 获取部门列表
     *
     * @return
     */
    @GetMapping()
    public Result list() {
        List<Dept> dept = deptService.list();
        return Result.success(dept);
    }
    @log
    @DeleteMapping("{id}")
    public Result delete(@PathVariable Integer id) {//PathVariable一般用指定查询
        deptService.delete(id);
        return Result.success();
    }
    @log
    @PostMapping()
    public Result add(@RequestBody Dept id) {
        deptService.add(id);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getDeptInfo(@PathVariable Integer id ){
        Dept deptS = deptService.infor(id);
        return Result.success(deptS);
    }
    @log
    @PutMapping()
    public Result upDate(@RequestBody Dept dept){
        deptService.upDate(dept);
        return Result.success();
    }

}
